<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;

class TempPushRecord extends Model
{
	use HasDateTimeFormatter;
    protected $table = 'eb_temp_push_record';
    protected $guarded = [];
    protected $fillable = ['user_id','temp_id'];
    public static function createTemp($user_id,$temp_id,$project_id = 0)
    {
        if($project_id){
            $tempPushRecord = TempPushRecord::query()
                ->where('project_id',$project_id)
                ->where('user_id',$user_id)
                ->where('temp_id',$temp_id)
                ->first();
            if($tempPushRecord){
                return false;
            }
        }
        $tempPushRecord = new TempPushRecord();
        $tempPushRecord->user_id = $user_id;
        $tempPushRecord->temp_id = $temp_id;
        $tempPushRecord->project_id = $project_id;
        $tempPushRecord->save();
        return $tempPushRecord;
    }
}
